// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.dao.impl;

import com.liuxinlong.modules.dao.AssetsDepartmentDao;
import com.liuxinlong.modules.entity.AssetsDepartment;
import com.liuxinlong.modules.mapper.AssetsDepartmentMapper;
import com.liuxinlong.utils.ObjectUtils;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * AssetsDepartmentDaoImpl
 *
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2024年01月11日
 */
@Service
public class AssetsDepartmentDaoImpl extends ServiceImpl<AssetsDepartmentMapper, AssetsDepartment> implements AssetsDepartmentDao {

    @Override
    public List<AssetsDepartment> pageAssetsDepartmentInfo(Map<String, Object> queryParam) {
        return baseMapper.pageAssetsDepartmentInfo(queryParam);
    }

    @Override
    public int getAssetsDepartmentInfoCount(Map<String, Object> queryParam) {
        return baseMapper.getAssetsDepartmentInfoCount(queryParam);
    }

    @Override
    public List<AssetsDepartment> getAssetsDepartmentList(Map<String, Object> queryParam) {
        return new ArrayList<>();
    }

    @Override
    public void deleteAssetsDepartmentById(String assetsId) {
        baseMapper.deleteAssetsDepartmentById(assetsId);
    }

    @Override
    public Map<String, Map<String, String>> getAssetsDepartmentMap() {
        return baseMapper.getAssetsDepartmentMap();
    }

    @Override
    public Map<String, Map<String, String>> getAssetsDepartmentMapBySn() {
        List<AssetsDepartment> departmentList = baseMapper.getAssetsDepartmentList();
        Map<String, Map<String, String>> resultMap = new HashMap<>();
        for (AssetsDepartment dep: departmentList) {
            Map<String, String> item = ObjectUtils.object2MapString(dep);
            if (dep.getDepartmentSn().contains(",")) {
                List<String> snList = Arrays.asList(dep.getDepartmentSn().split(","));
                for (String sn: snList) {
                    resultMap.put(sn,item);
                }
            } else {
                resultMap.put(dep.getDepartmentSn(),item);
            }
        }
        return resultMap;
//        return baseMapper.getAssetsDepartmentMapBySn();
    }

}
